package com.lincong;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Set;

/**
 * @author linchong
 * @version 1.0
 * @Date: 2022-05-04 16:16
 * @Description: HelloServlet$
 */
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {

	@Override
	public void init() throws ServletException {
		System.out.println("初始化Servlet...");
	}

	@Override
	public void destroy() {
		System.out.println("结束");
	}

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("doGet,方法入口");
		doGet(req, resp);
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String name = "hello spring";
		req.setAttribute("name",name);
		req.getRequestDispatcher("/WEB-INF/jsp/hello.jsp").forward(req,resp);
	}
}
